
package com.yuan.servlet;

import com.yuan.hibernate.员工信息表;
import com.yuan.hibernate.员工信息表DAO;
import com.yuan.hibernate.考勤表;
import com.yuan.hibernate.考勤表DAO;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class checkservlet extends BaseHttpServlet {
    private 考勤表DAO m考勤表DAO = null;
    private 员工信息表 m员工信息表 = null;
    private 员工信息表DAO m员工信息表DAO = null;
    private List<考勤表> list = null;
    private List<考勤表> anList = null;

    @SuppressWarnings({
            "unchecked", "rawtypes"
    })
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        super.doGet(request, response);
        String data = request.getParameter("data");
        int id = Integer.parseInt(request.getParameter("id"));
        m员工信息表DAO = new 员工信息表DAO();
        m考勤表DAO = new 考勤表DAO();
        m员工信息表 = m员工信息表DAO.findById(id);
        list = m考勤表DAO.findBy职工姓名(m员工信息表.get姓名());
        anList = new ArrayList();
        try {
            for (考勤表 temp : list) {
                if (temp.getId().get日期().startsWith(data))
                {
                    anList.add(temp);
                    mResponse = com.yuan.util.JsonUtils.getFromList(anList);
                    mResponse = mResponse.replace("{\"id\":", "");
                    mResponse = mResponse.replace("},\"位置\"", ",\"位置\"");
                }
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        if (mResponse == null)
            mResponse = "今天没有考勤记录";
        closeAndClear();
    }

    protected synchronized void closeAndClear() {
        m考勤表DAO = null;
        m员工信息表 = null;
        m员工信息表DAO = null;
        list = null;
        anList = null;
        super.closeAndClear();
    }
}
